import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by lenovo on 2018/5/24.
 */
public class Out extends JFrame implements ActionListener {
    JPanel submin, money;
    JButton yes, re;
    JTextField jtf;
    JLabel text;
    User user;

    public static void main(String[] args) {
        Out in = new Out(null);
    }

    public Out(User u) {
        user = u;
        money = new JPanel();
        submin = new JPanel();
        text = new JLabel("提现金额");

        yes = new JButton("确定");
        re = new JButton("返回");
        jtf = new JTextField(10);

        money.add(text);
        money.add(jtf);
        submin.add(re);
        submin.add(yes);


        re.addActionListener(this);
        yes.addActionListener(this);

        this.add(money);
        this.add(submin);
        this.setSize(250, 125);
        this.setLocationRelativeTo(null);//在屏幕中间显示(居中显示)
        this.setLayout(new GridLayout(2, 1));//网格式布局
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);//退出关闭JFrame
        this.setTitle("提现");//窗体标签
        this.setVisible(true);
        this.setResizable(false);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand() == "确定") {
            int value = user.getMoney() - Integer.parseInt(jtf.getText());
            if (value < 0) {
                JOptionPane.showMessageDialog(null, "余额不足", "提示消息", JOptionPane.WARNING_MESSAGE);
            } else {
                ExInform.addMoney(user, value);
                user.setMoney(value);
                new Funds(user);
                this.dispose();
            }
        }
        if (e.getActionCommand() == "返回") {
            new Funds(user);
            this.dispose();
        }
    }
}
